<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
</head>
<style>
    .timeLine {
        width: 100%;
        display: -webkit-flex;
        display: flex;
        flex-direction: row;
    }

    .timeLineImg {
        width: 20%;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .timeLineLeft {
        height: 100%;
        width: 2px;
        border-left: 1px solid #B0B0B0;
    }

    .timeLineInfo {
        width: 80%;
    }

    .timeLineInfoTitle {
        font-size: 20px;
        color: #3f51b5;
    }

    .timeLineInfoIntroduce {
        font-size: 16px;
        color: #0062cc;
    }

    .timeLineInfoTime {
        font-size: 12px;
        color: #CA92C4;
    }

    .scoll {
        overflow: auto;
        margin-top: 65px;
    }

    .aui-list .aui-list-item:after {
        width: 100%;
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: auto;
        right: auto;
        bottom: 0;
        left: 0;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-list:before {
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: 0;
        left: 0;
        right: auto;
        bottom: auto;
        width: 100%;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-card-list-header {
        color: #212121;
        font-size: 22px;
        font-weight: 600;
    }

    #addEmpBtn:before {
        content: url(../image/pn.png);
    }

    #addMrlBtn:before {
        content: url(../image/pn.png);
    }
</style>

<body style="padding-bottom: 3rem;">
    <div style="height:114px;width:100%;position: fixed;top: 0px;bottom: auto;table-layout: fixed;z-index: 10;">
        <header class="aui-bar aui-bar-nav" style="position:fixed;" id="header">
            <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title" id="title">
                设备保养
            </div>
        </header>
        <div class="aui-tab aui-border-b" id="tab" style="margin-top:50px;">
            <div class="aui-tab-item aui-active">基础信息</div>
            <div class="aui-tab-item">保养明细</div>
            <div class="aui-tab-item">保养人员</div>
            <div class="aui-tab-item" id="selectMrlTab" style="display: none;">更换备件</div>
        </div>
    </div>
    <div class="aui-padded-5 " id="tab1-con" style="margin-top: 90px;">
        <div id="tab1-con1">
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list ui-selectee">
                        <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                            <ul class="aui-list aui-form-list" style="content: none;line-height: 2rem;font-size: 17px;">
                                <li class="aui-list-item"
                                    style="content: none;border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">保养单号</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="taskCode" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="content: none;border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">设备编码</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipCode" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">设备名称</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipName" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">规格型号</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipModel" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">设备类别</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipType" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">保养班组</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="ext01" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">保养人员</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="emPlanEmpArrStr" value="" />
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <!-- 处理意见 -->
        <div class="aui-hide" id="tab1-con2">
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list ui-selectee">
                        <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                            <ul class="aui-list aui-form-list" style="content: none;">
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label" style="width: 45%;">开始时间</div>
                                        <div class="aui-list-item-input" style="padding-top: 0.75rem;">
                                            <input class="form-control" type="datetime-local" step="1" id="beginDate"
                                                placeholder="请选择">
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label" style="width: 45%;">结束时间</div>
                                        <div class="aui-list-item-input" style="padding-top: 0.75rem;">
                                            <input class="form-control" type="datetime-local" step="1" id="endDate"
                                                placeholder="请选择">
                                            <!-- <input  class="form-control" type="text" id="endDate"
                                                 placeholder="请选择"> -->
                                        </div>
                                    </div>
                                </li>

                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label ui-selectee" style="width: 45%;">保养用时(分)</div>
                                        <div class="aui-list-item-input ui-selectee"> <input class="form-control"
                                                type="text" id="consumeTime">
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label ui-selectee" style="width: 45%;">是否停机</div>
                                        <div class="aui-list-item-input"
                                            style="display: flex; align-items: center; gap: 15px;">
                                            <!-- 用flex容器包裹单选按钮组，使子元素横向排列 -->
                                            <div style="display: flex; align-items: center;">
                                                <input class='aui-radio' type='radio' name="ext05"
                                                    style="margin-right: 6px;" value='1'>
                                                <div class='aui-radio-name'>是</div>
                                            </div>
                                            <div style="display: flex; align-items: center;">
                                                <input class='aui-radio' type='radio' name="ext05"
                                                    style="margin-right: 6px;" value='0'>
                                                <div class='aui-radio-name'>否</div>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item" id="ext08Li"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;display: none;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label ui-selectee" style="width: 45%;">停机时长(分)</div>
                                        <div class="aui-list-item-input ui-selectee"> <input class="form-control"
                                                type="text" id="ext08">
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label ui-selectee" style="width: 45%;">是否更换备件</div>
                                        <div class="aui-list-item-input"
                                            style="display: flex; align-items: center; gap: 15px;">
                                            <!-- 用flex容器包裹单选按钮组，使子元素横向排列 -->
                                            <div style="display: flex; align-items: center;">
                                                <input class='aui-radio' type='radio' name="ext06"
                                                    style="margin-right: 6px;" value='1'>
                                                <div class='aui-radio-name'>是</div>
                                            </div>
                                            <div style="display: flex; align-items: center;">
                                                <input class='aui-radio' type='radio' name="ext06"
                                                    style="margin-right: 6px;" value='0'>
                                                <div class='aui-radio-name'>否</div>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label ui-selectee" style="width: 45%;">维修描述</div>
                                        <div class="aui-list-item-input">
                                            <textarea id="ext07" name="feedback" placeholder="输入信息..." required
                                                maxlength="1000"></textarea>

                                        </div>
                                    </div>
                                </li>
                                <!-- <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label ui-selectee" style="width: 45%;">保养图片</div>
                                        <div class="aui-content" style="background-color: #ffffff">
                                            <ul class="aui-list-view aui-grid-view" id="imgslist">
                                                <li class="aui-list-view-cell aui-img aui-col-xs-4 aui-padded-5"
                                                    id="addpic" onclick="imgClick()">
                                                    <img class="aui-img-object" src="../image/add.jpg">
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </li> -->
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">保养图片</div>
                                        <div class="aui-list-item-input">
                                            <div class="aui-content" style="background-color: #ffffff">
                                                <ul class="aui-list-view aui-grid-view" id="imgslist">
                                                    <li class="aui-list-view-cell aui-img aui-col-xs-4 aui-padded-5"
                                                        id="addpic" onclick="imgClick()">
                                                        <img class="aui-img-object" style="padding: 5px;"
                                                            src="../image/add.jpg">
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                            <ul class="aui-list aui-form-list" style="content: none;" id="citemForm">


                            </ul>
                        </div>
                    </div>
                </div>
            </div>


        </div>
        <!-- 工作量 -->
        <div class="aui-hide" id="tab1-con3">
            <div class="aui-btn aui-btn-block" style="background-color:#ffffff;" onclick="goSelectEmp()">
                <!-- <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 0.7rem" id="addEmpBtn">增加人员</i> -->
                <div class="aui-btn aui-btn-info"
                    style="width:98%;margin-left:1px;border: 1px dashed #808680;background-color: #83cff2 !important;">+
                    新增人员</div>
            </div>
            <ul class="ui-selectee" id="tbodyHtml" style="margin-bottom:2.25rem;">
                <!-- <li class='sortable ui-selectee ui-sortable' name='litr'>
                    <ul class='aui-list aui-media-list ui-selectee'>
                        <li class='aui-list-item ui-selectee'
                            style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>
                            <div class='aui-media-list-item-inner ui-selectee'>
                                <div class='aui-list-item-inner ui-selectee'>
                                    <div class='aui-list-item-text ui-selectee'>
                                        <div class='aui-list-item-title ui-selectee' name='empName'>赵成刚</div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee'>
                                        <div class='aui-list-item-label ui-selectee list-tr-title'>人员编码</div>
                                        <div class='aui-list-item-inner ui-selectee' name='empCode'>950064</div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                                        <div class='aui-list-item-label ui-selectee list-tr-title'>班组</div>
                                        <div class='aui-list-item-inner ui-selectee'>终检班组</div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                                        <div class='aui-list-item-label ui-selectee list-tr-title'>维修工时(分)</div>
                                        <div class='aui-list-item-inner ui-selectee'><input type='number'
                                                name='actualtime' οnkeyup='value=value.replace(/[^d]/g,'')'
                                                style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;'
                                                value='0'></div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee'>
                                        <div class='aui-list-item-label ui-selectee'></div>
                                        <div class='aui-list-item-right aui-btn ui-selectee delEmp'
                                            style='background:#d41a10;color:#f5f5f5;'>删除</div>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </li>
                <li class='sortable ui-selectee ui-sortable' name='litr'>
                    <ul class='aui-list aui-media-list ui-selectee'>
                        <li class='aui-list-item ui-selectee'
                            style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>
                            <div class='aui-media-list-item-inner ui-selectee'>
                                <div class='aui-list-item-inner ui-selectee'>
                                    <div class='aui-list-item-text ui-selectee'>
                                        <div class='aui-list-item-title ui-selectee' name='empName'>李世超</div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee'>
                                        <div class='aui-list-item-label ui-selectee list-tr-title'>人员编码</div>
                                        <div class='aui-list-item-inner ui-selectee' name='empCode'>950115</div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                                        <div class='aui-list-item-label ui-selectee list-tr-title'>班组</div>
                                        <div class='aui-list-item-inner ui-selectee'>终检班组</div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                                        <div class='aui-list-item-label ui-selectee list-tr-title'>维修工时(分)</div>
                                        <div class='aui-list-item-inner ui-selectee'><input type='number'
                                                name='actualtime' οnkeyup='value=value.replace(/[^d]/g,'')'
                                                style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;'
                                                value='0'></div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee'>
                                        <div class='aui-list-item-label ui-selectee'></div>
                                        <div class='aui-list-item-right aui-btn ui-selectee delEmp'
                                            style='background:#d41a10;color:#f5f5f5;'>删除</div>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </li>
                <li class='sortable ui-selectee ui-sortable' name='litr'>
                    <ul class='aui-list aui-media-list ui-selectee'>
                        <li class='aui-list-item ui-selectee'
                            style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>
                            <div class='aui-media-list-item-inner ui-selectee'>
                                <div class='aui-list-item-inner ui-selectee'>
                                    <div class='aui-list-item-text ui-selectee'>
                                        <div class='aui-list-item-title ui-selectee' name='empName'>巴旭东</div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee'>
                                        <div class='aui-list-item-label ui-selectee list-tr-title'>人员编码</div>
                                        <div class='aui-list-item-inner ui-selectee' name='empCode'>950021</div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                                        <div class='aui-list-item-label ui-selectee list-tr-title'>班组</div>
                                        <div class='aui-list-item-inner ui-selectee'>终检班组</div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                                        <div class='aui-list-item-label ui-selectee list-tr-title'>维修工时(分)</div>
                                        <div class='aui-list-item-inner ui-selectee'><input type='number'
                                                name='actualtime' οnkeyup='value=value.replace(/[^d]/g,'')'
                                                style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;'
                                                value='0'></div>
                                    </div>
                                    <div class='aui-list-item-text ui-selectee'>
                                        <div class='aui-list-item-label ui-selectee'></div>
                                        <div class='aui-list-item-right aui-btn ui-selectee delEmp'
                                            style='background:#d41a10;color:#f5f5f5;'>删除</div>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </li> -->
            </ul>
        </div>

        <div class="aui-hide" id="tab1-con4">
            <!-- <div class="aui-btn aui-btn-block" style="background-color:#ffffff;" onclick="goSelectMrl()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 0.7rem" id="addEmpBtn">增加备件</i>
            </div> -->
            <div class="aui-btn aui-btn-block" style="background-color:#ffffff;" onclick="goSelectMrl()">
                <div class="aui-btn aui-btn-info"
                    style="width:98%;margin-left:1px;border: 1px dashed #808680;background-color: #83cff2 !important;">
                    更换备件</div>
            </div>
            <ul class="ui-selectee" id="tbodyMrlHtml" style="margin-bottom:2.25rem;">

            </ul>
        </div>


    </div>
    <footer class="aui-bar aui-bar-tab ui-selectee" style="color: #f5f5f5;border: 1px solid #dad5d5;">
        <div class="aui-content" style="background-color: red;">
            <ul class="aui-list-view aui-grid-view">
                <li class="aui-list-view-cell aui-img aui-col-xs-6 aui-padded-5">
                    <div style="width:100%;margin-left:2%;">
                        <p id='totalCount'></p>
                    </div>
                </li>
                <li class="aui-list-view-cell aui-img aui-col-xs-3 aui-padded-5" style="margin-top: 0.25rem;">
                    <div class="aui-btn aui-btn-info" style="width:98%;margin-left:1px;" onclick="doComplete('2')">保存
                    </div>
                </li>
                <li class="aui-list-view-cell aui-img aui-col-xs-3 aui-padded-5" style="margin-top: 0.25rem;">
                    <div class="aui-btn aui-btn-info" style="width:98%;margin-left:1px;" onclick="doCompleteBefore()">完成
                    </div>
                </li>
            </ul>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/aui-tab.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/jdate.min.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script>
    var listItem = [];//检验项
    var imageFilter = null;
    var imageBrowser = null;
    var uiMediaScanner = null;
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
    apiready = function () {
        api.parseTapmode();
        // 引入多选模块
        uiMediaScanner = api.require('UIMediaScanner');
        // 引入过滤压缩模块
        imageFilter = api.require("imageFilter");
        // 引入图片浏览模块
        imageBrowser = api.require('imageBrowser');

        getEmequipmentDataInfo();

        //是否停机绑定change事件
        const radioStopButtons = document.querySelectorAll('input[name="ext05"]');
        // 为每个单选按钮添加change事件监听
        radioStopButtons.forEach(radio => {
            radio.addEventListener('change', function () {
                // 检查当前单选按钮是否被选中
                if (this.checked) {
                    // 获取选中的值
                    const selectedValue = this.value;
                    //判断若 是否停机选择为是 则显示“停机时长”文本框，否则隐藏“停机时长”文本框
                    const ext08Input = document.getElementById('ext08Li');
                    if ('1' == selectedValue) {
                        ext08Input.style.display = 'block';
                    } else {
                        ext08Input.style.display = 'none';
                    }

                }
            });
        });

        //是否更换备件绑定change事件
        const radioChangeButtons = document.querySelectorAll('input[name="ext06"]');
        // 为每个单选按钮添加change事件监听
        radioChangeButtons.forEach(radio => {
            radio.addEventListener('change', function () {
                // 检查当前单选按钮是否被选中
                if (this.checked) {
                    // 获取选中的值
                    const selectedValue = this.value;
                    //判断若 是否更换备件选择为是 则显示“更换备件”Tab，否则隐藏“更换备件”Tab
                    const selectMrlTab = document.getElementById('selectMrlTab');
                    if ('1' == selectedValue) {
                        selectMrlTab.style.display = 'block';
                    } else {
                        selectMrlTab.style.display = 'none';
                    }

                }
            });
        });


        //查询班组下拉框
        // doSearchTeamGid();
    }

    var tab = new auiTab({
        element: document.getElementById("tab"),

    }, function (ret) {
        if (ret) {
            //定义获取对象的所有兄弟节点的函数，
            function siblings(elm) {
                var a = [];
                var p = elm.parentNode.children;
                for (var i = 0; i < p.length; i++) {
                    if (p[i] !== elm) a.push(p[i]);
                }
                return a;
            }
            var index = ret.index;
            var activeC = document.getElementById("tab1-con" + index);
            activeC.className = "";
            for (var i = 0; i < siblings(activeC).length; i++) {
                siblings(activeC)[i].className = "aui-hide";
            }


        }
    });



    // 转换Date对象为datetime-local所需的格式 (YYYY-MM-DDThh:mm)
    function formatDateTime(inputId) {
        const input = document.getElementById(inputId);
        if (!input.value) return "";

        // 将输入值转换为Date对象
        const date = new Date(input.value);

        // 获取各时间部分并补零
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0'); // 秒数默认取当前

        // 拼接成目标格式
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    }

    document.getElementById('beginDate').addEventListener('change', setConsumeTime);
    document.getElementById('endDate').addEventListener('change', setConsumeTime);

    //计算保养用时
    function setConsumeTime() {
        //开始时间
        var beginDate = $("#beginDate").val();
        //结束时间
        var endDate = $("#endDate").val();
        if (beginDate != null && beginDate != '' && endDate != null && endDate != '') {
            const begin = new Date(beginDate);
            const end = new Date(endDate);

            // 检查日期有效性
            if (isNaN(begin.getTime()) || isNaN(end.getTime())) {
                // diffResult.textContent = "时间格式无效";
                // diffResult.classList.add('text-red-600');
                return;
            }

            // 检查结束时间是否早于开始时间
            if (end < begin) {
                // diffResult.textContent = "结束时间不能早于开始时间";
                // diffResult.classList.add('text-red-600');
                return;
            }

            // 计算毫秒差，转换为分钟
            const diffMs = end - begin;
            const diffMinutes = Math.floor(diffMs / (1000 * 60));
            $("#consumeTime").val(diffMinutes);
        }


    }

    function imgClick() {
        // 获取图片宽高
        var normalW = $("#addpic img").width();
        api.actionSheet({
            title: '选择图片来源',
            buttons: ['照相机', '浏览相册']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            switch (index) {
                // 拍照
                case 1:
                    // 打开拍照
                    api.getPicture({
                        sourceType: "camera",
                        encodingType: "jpg",
                        destinationType: "url",
                        mediaValue: "pic",
                        quality: 50,
                        saveToPhotoAlbum: true
                    }, function (ret, err) {
                        if (ret && ret.data) {
                            // 拍照返回的本地路径
                            var returnUrl = ret.data;
                            // 图片压缩
                            imgCompress(returnUrl, 0.5, 0.5, getExt(returnUrl), function (compressImg) {
                                var showImgHtml = "<li class='aui-list-view-cell aui-img aui-col-xs-4  aui-padded-5' style='margin-left: 5px;width:" + normalW + "px;height:" + normalW + "px;' onclick='lookImg(\"" + compressImg + "\")'><img class='aui-img-object' src='" + compressImg +
                                    "' style='width:" + normalW + "px;height:" + normalW + "px;'></li>";
                                // 追加图片
                                $("#addpic").before(showImgHtml);
                                // ########################################  绑定长按事件 ########################
                                addPress($("#imgslist img[src='" + compressImg + "']").parent("li"));
                                // console.log("imgsimgsimgsimgs666:"+JSON.stringify(content.innerHTML));
                                //上传图片
                                uploadFile(compressImg);
                            });
                        } else {
                            api.toast({
                                msg: '没有选择，或者选择出错'
                            });
                        }
                    });
                    break;
                // 打开图片选择器
                case 2:
                    uiMediaScanner.open({
                        type: 'picture',
                        column: 4,
                        classify: true,
                        max: 5,
                        sort: {
                            key: 'time',
                            order: 'desc'
                        },
                        texts: {
                            stateText: '已选*项',
                            cancelText: '取消',
                            finishText: '完成'
                        },
                        styles: {
                            bg: '#fff',
                            mark: {
                                icon: '',
                                position: 'bottom_left',
                                size: 20
                            },
                            nav: {
                                bg: '#b23e4b',
                                stateColor: '#fff',
                                stateSize: 18,
                                cancelBg: 'rgba(0,0,0,0)',
                                cancelColor: '#fff',
                                cancelSize: 18,
                                finishBg: 'rgba(0,0,0,0)',
                                finishColor: '#fff',
                                finishSize: 18
                            }
                        }
                    }, function (ret) {
                        if (ret) {
                            if (ret.list) {
                                for (var i = 0; i < ret.list.length; i++) {
                                    var selectImg = ret.list[i];
                                    // 获取图片的路径
                                    var selectimgPath = selectImg.path;
                                    var selectimgThumbPath = selectImg.thumbPath;
                                    // 图片压缩
                                    imgCompress(selectimgPath, 0.5, 0.5, selectImg.suffix, function (compressImg) {
                                        var showImgHtml = "<li class='aui-list-view-cell aui-img aui-col-xs-4 aui-padded-5' style='margin-left: 5px;width:" + normalW + "px;height:" + normalW + "px;'  onclick='lookImg(\"" + compressImg + "\")'><img class='aui-img-object' src='" + compressImg +
                                            "' style='width:" + normalW + "px;height:" + normalW + "px;'></li>";
                                        // 追加图片
                                        $("#addpic").before(showImgHtml);
                                        // ########################################  绑定长按事件 ########################
                                        addPress($("#imgslist img[src='" + compressImg + "']").parent("li"));

                                        // ################### 上传图片 #########################
                                        uploadFile(compressImg);
                                    });
                                }
                            }
                        }
                    });
                    break;
            }
        });
    }

    // 上传图片
    // url：上传的url地址
    // data：上传的文件
    // callback：上传成功返回地址
    function uploadFile(data) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/uploadPhotosAPP";
        var data = {
            values: {
                un: un
            },
            files: {
                file: data
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == "0") {
                    console.log("上传成功");
                } else if (myobj.code == "1") {
                    alert("上传失败");
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    // 图片压缩
    // imgsrc：源图片的路径
    // quality：图片压缩质量，一般建议0.5
    // scale：图片压缩比例，也是建议0.5
    // ext：源图片拓展名
    // callback：转换成功之后回调函数
    function imgCompress(imgsrc, quality, scale, ext, callback) {
        // 压缩文件的保存目录
        var savePath = api.cacheDir + "/" + getNowFormatDate() + "/";
        // 压缩文件生成的随机文件名称
        var savename = NewGuid() + "." + ext;
        imageFilter.compress({
            img: imgsrc,
            quality: quality,
            scale: quality,
            save: {
                album: false,
                imgPath: savePath,
                imgName: savename
            }
        }, function (ret, err) {
            if (ret) {
                callback(savePath + savename);
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    // 打开图片浏览
    // imgs：需要预览的图片集合
    function openImageBrowser(imgs) {
        imageBrowser.openImages({
            imageUrls: imgs,
            showList: false,
            activeIndex: 0
        });
    }

    // 获取文件拓展名
    function getExt(fileName) {
        return fileName.substring(fileName.lastIndexOf('.') + 1);
    }

    // 生成guid,主要用于生成随机文件名
    function NewGuid() {
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }

        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    }

    // 添加长按方法
    function addPress(obj, index) {
        // 获取目前长按的对象
        var hammertime = new Hammer(obj[0]);
        // 绑定长按对象
        hammertime.on("press", function (e) {
            api.confirm({
                title: '温馨提示',
                msg: '您确定要删除该图片吗？',
                buttons: ['确定', '取消']
            }, function (ret, err) {
                if (ret.buttonIndex == 1) {
                    // 移除自己
                    $(obj).remove();
                    api.toast({
                        msg: '删除成功！'
                    });
                }
            });
        });
    }

    // 获取当前的时间，拼接成2015-11-09这样的格式，主要用于对图片进行时间分类
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate
        return currentdate;
    }

    //获取计划关联人员信息
    function getEmPlanEmpDataList(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getemPlanEmpDataList";
        var data = {
            values: {
                sysid: sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<li class='sortable ui-selectee ui-sortable' name='litr'>";
                        html += "<ul class='aui-list aui-media-list ui-selectee'>";
                        html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
                        html += "<div class='aui-media-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-title ui-selectee' name='empName' title='" + list[i].empName + "'>" + list[i].empName + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>人员编码</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' name='empCode'>" + list[i].empCode + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>班组</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].groupName + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>维修工时(分)</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'><input type='number' name='actualtime' οnkeyup='value=value.replace(/[^\d]/g,'')' ";
                        html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' value='" + list[i].actualtime + "'></div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee'></div>";
                        html += "<div class='aui-list-item-right aui-btn ui-selectee delEmp' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    //console.log(html);
                    //console.log($api.byId("tbodyHtml"));
                    $api.html($api.byId("tbodyHtml"), html);
                    //console.log($("#tbodyHtml").html());

                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }



    //获取信息
    function getEmequipmentDataInfo() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEmequipmentDataInfo";
        var data = {
            values: {
                equipCode: api.pageParam.equipcode,
                taskCode: api.pageParam.taskCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    $("#taskCode").val(api.pageParam.taskCode);
                    $("#equipCode").val(api.pageParam.equipcode);
                    $("#equipName").val(myobj.equipName);
                    $("#equipModel").val(myobj.equipModel);
                    $("#equipType").val(myobj.equipType);
                    $("#ext01").val(myobj.ext01);
                    $("#emPlanEmpArrStr").val(myobj.emPlanEmpArrStr);

                    //开始时间
                    if (myobj.beginDate != null && myobj.beginDate != undefined && myobj.beginDate != '') {
                        const beginDate = myobj.beginDate.replace(' ', 'T').slice(0, 16);
                        $("#beginDate").val(beginDate);
                    }
                    //结束时间
                    if (myobj.endDate != null && myobj.endDate != undefined && myobj.endDate != '') {
                        const endDate = myobj.endDate.replace(' ', 'T').slice(0, 16);
                        $("#endDate").val(endDate);
                    }
                    //保养用时
                    $("#consumeTime").val(myobj.consumeTime);
                    //是否停机
                    // $("#ext05").val(myobj.ext05);
                    if (myobj.ext05 != null && myobj.ext05 != '') {
                        const radioGroup5 = document.getElementsByName('ext05');
                        // 遍历找到对应value的单选按钮并设置选中
                        for (let radio of radioGroup5) {
                            if (radio.value === myobj.ext05) {
                                radio.checked = true;
                                if ('1' == radio.value) {//显示停机时长
                                    const ext08Input = document.getElementById('ext08Li');
                                    ext08Input.style.display = 'block';
                                    $("#ext08").val(myobj.ext08 == null || myobj.ext08 == undefined || myobj.ext08 == '' ? 0 : myobj.ext08);
                                }
                                break; // 找到后退出循环
                            }
                        }
                    }

                    //是否更换备件
                    // $("#ext06").val(myobj.ext06);
                    if (myobj.ext06 != null && myobj.ext06 != '') {
                        const radioGroup6 = document.getElementsByName('ext06');
                        // 遍历找到对应value的单选按钮并设置选中
                        for (let radio of radioGroup6) {
                            if (radio.value === myobj.ext06) {
                                radio.checked = true;
                                if ('1' == radio.value) {//显示更换备件Tab
                                    const selectMrlTab = document.getElementById('selectMrlTab');
                                    selectMrlTab.style.display = 'block';
                                }
                                break; // 找到后退出循环
                            }
                        }
                    }
                    //维修描述
                    $("#ext07").val(myobj.ext07);
                    //保养图片
                    var picNames = eval(myobj.picNames);
                    createImgList(picNames);
                    //检验项
                    listItem = eval(myobj.list);
                    creatHtml(listItem);
                    //保养人员
                    var listEmp = eval(myobj.listEmp);
                    setEmployeeList(listEmp);
                    //备件
                    var bjList = eval(myobj.bjList);
                    sparePartsSelected(bjList);

                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //初始化显示上次保存的图片
    function createImgList(picNames) {
        var normalW = $("#addpic img").width();
        for (var i = 0; i < picNames.length; i++) {
            var showImgHtml = "<li class='aui-list-view-cell aui-img aui-col-xs-4 aui-padded-5' style='margin-left: 5px;width:" + normalW + "px;height:" + normalW + "px;'  onclick='lookImg(\"" + picNames[i].addr + "\")'><img class='aui-img-object' src='" + picNames[i].addr +
                "' style='width:" + normalW + "px;height:" + normalW + "px;' id='" + picNames[i].fileName + "'></li>";
            $("#addpic").before(showImgHtml);
            // ########################################  绑定长按事件 ########################
            addPress($("#imgslist img[src='" + picNames[i].addr + "']").parent("li"));
        }

    }

    function creatHtml(listItem) {
        var hascheck = 0;
        for (var i = 0; i < listItem.length; i++) {
            if (listItem[i].chk_result != null && listItem[i].chk_result != undefined && listItem[i].chk_result != '') {
                hascheck = hascheck + 1;
            }
        }
        document.getElementById("totalCount").innerHTML = '共' + listItem.length + '项 </br> 已保养' + hascheck + ' 未保养' + (listItem.length - hascheck);
        $("#citemForm").children().remove();

        for (var i = 0; i < listItem.length; i++) {
            var citemId = listItem[i].sysid;
            var citemName = listItem[i].chk_item_name;
            var chk_result = listItem[i].chk_result;

            var divStr = "<li class='aui-list-item' style='border-bottom: 1px solid #eee; padding: 10px 0; margin-bottom: 1px;padding-left: 0.75rem;'>";
            divStr = divStr + "<div class='aui-list-item-inner' style='display: flex; flex-direction: column; align-items: flex-start;'>";
            divStr = divStr + "<div class='aui-list-item-label ui-selectee' style='width: 100%; margin-bottom: 8px;'>" + citemName + "</div>";
            divStr = divStr + "<div class='aui-list-item-input' style='display: flex; align-items: center; gap: 15px; width: 100%;'>";
            divStr = divStr + "<div style='display: flex; align-items: center;'>";
            if (chk_result != null && chk_result == 1) {
                divStr = divStr + "<input class='aui-radio' type='radio' name=\"" + citemId + "\" style='margin-right: 6px;' checked onchange='setResult(\"" + citemId + "\",\"" + 1 + "\");' value='1'>";
            } else {
                divStr = divStr + "<input class='aui-radio' type='radio' name=\"" + citemId + "\" style='margin-right: 6px;' onchange='setResult(\"" + citemId + "\",\"" + 1 + "\");' value='1'>";
            }

            divStr = divStr + "<div class='aui-radio-name'>OK</div>";
            divStr = divStr + "</div>";
            divStr = divStr + "<div style='display: flex; align-items: center;'>";
            if (chk_result != null && chk_result == 2) {
                divStr = divStr + "<input class='aui-radio' type='radio' name=\"" + citemId + "\" checked onchange='setResult(\"" + citemId + "\",\"" + 2 + "\");' style='margin-right: 6px;' value='2'>";
            } else {
                divStr = divStr + "<input class='aui-radio' type='radio' name=\"" + citemId + "\" onchange='setResult(\"" + citemId + "\",\"" + 2 + "\");' style='margin-right: 6px;' value='2'>";
            }

            divStr = divStr + "<div class='aui-radio-name'>NG</div>";
            divStr = divStr + "</div>";
            divStr = divStr + "</div>";
            divStr = divStr + "</div>";
            divStr = divStr + "</li>";


            $("#citemForm").append(divStr);
        }

    }
    function setResult(taskItemId, value) {
        var hascheck = 0;
        var error = 0;
        for (var i = 0; i < listItem.length; i++) {
            if (listItem[i].sysid == taskItemId) {
                listItem[i].chk_result = value;
            }
            if (listItem[i].chk_result != null && listItem[i].chk_result != undefined && listItem[i].chk_result != '') {
                hascheck = hascheck + 1;
                if (listItem[i].chk_result == '2') {
                    error = error + 1;
                }
            }
        }
        document.getElementById("totalCount").innerHTML = '共' + listItem.length + '项 </br> 已保养' + hascheck + ' 未保养' + (listItem.length - hascheck);
    }

    //选择保养人员
    function goSelectEmp() {
        //判断当前是否已选择了保养人员，是则再选择人时只能选已选过的保养人员班组的人
        var count = $("ul[id=tbodyHtml] li[name=litr]").length;//已选择的保养人员数量
        var teamID = '';
        if (count > 0) {
            var empCode = document.getElementsByName("empCode")[0].innerText;
            teamID = document.getElementById("teamID" + empCode).value;
        }
        api.openWin({
            name: 'mdEmployeeSelect',
            url: 'mdEmployeeSelect.html',
            pageParam: {
                name: "emequipmentMaintenance-detail",
                teamID: teamID
            }
        });
    }

    //人员选择后回调函数
    function setEmployeeList(dataList) {
        var list = dataList; //JSON.parse(dataList);
        var html = "";

        var listEmp = [];//已选择人员编码，若人员编码已存在将不会重复添加
        $("ul[id=tbodyHtml] li[name=litr]").each(function (index) {
            var empCode = document.getElementsByName("empCode")[index].innerText;
            listEmp.push(empCode);
        })

        for (i in list) {
            if (listEmp.indexOf(list[i].code) == -1) {
                // console.log("人员选择后回调函数:" + list[i].teamGid);
                html += "<li class='sortable ui-selectee ui-sortable' name='litr'>";
                html += "<ul class='aui-list aui-media-list ui-selectee'>";
                html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
                html += "<div class='aui-media-list-item-inner ui-selectee'>";
                html += "<div class='aui-list-item-inner ui-selectee'>";
                html += "<div class='aui-list-item-text ui-selectee'>";
                html += "<div class='aui-list-item-title ui-selectee' name='empName'>" + list[i].name + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>人员编码</div>";
                html += "<div class='aui-list-item-inner ui-selectee' name='empCode'>" + list[i].code + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>班组</div>";
                html += "<div class='aui-list-item-inner ui-selectee' name='teamNameS'>" + list[i].teamName + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;display:none;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>班组主键</div>";
                html += "<div class='aui-list-item-inner ui-selectee' ><input type='text' id='teamID" + list[i].code + "'  value='" + list[i].teamGid + "'>"

                    // + list[i].teamGid + 
                    + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>维修工时(分)</div>";
                html += "<div class='aui-list-item-inner ui-selectee'><input type='number' name='actualtime'  οnkeyup='value=value.replace(/[^\d]/g,'')' ";
                html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' value='"
                    + (list[i].actualtime == null || list[i].actualtime == undefined || list[i].actualtime == '' ? 0 : list[i].actualtime) + "'></div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee'>";
                html += "<div class='aui-list-item-label ui-selectee'></div>";
                html += "<div class='aui-list-item-right aui-btn ui-selectee delEmp' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
                html += "</div>";
                html += "</div>";
                html += "</div>";
                html += "</li>";
                html += "</ul>";
                html += "</li>";
            }

        }
        // console.log("htmlhtml:" + html);
        $api.append($api.byId("tbodyHtml"), html);
        refreshTab1Emp();

    }

    //删除人员
    $(document).on('click', '.delEmp', function () {
        var othis = this;
        api.confirm({
            title: '删除',
            msg: '确认删除该人员信息？',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                $(othis).parent().parent().parent().parent().parent().parent().remove();
                refreshTab1Emp();
            } else { }
        });


    })

    //刷新 基础信息tab 保养班组、保养人员
    function refreshTab1Emp() {
        var ext01 = "";//班组名称
        var emPlanEmpArrStr = "";//保养人员名称，逗号拼接
        $("ul[id=tbodyHtml] li[name=litr]").each(function (index) {
            var empName = document.getElementsByName("empName")[index].innerText;
            ext01 = document.getElementsByName("teamNameS")[index].innerText;
            emPlanEmpArrStr = emPlanEmpArrStr == "" ? empName : (emPlanEmpArrStr + "," + empName);
        })
        //更新tab【基础信息】保养班组、保养人员
        $("#ext01").val(ext01);
        $("#emPlanEmpArrStr").val(emPlanEmpArrStr);
    }

    //选择备件
    function goSelectMrl() {
        api.openWin({
            name: 'emequipmentfaltSelectSpareParts',
            url: 'emequipmentfaltSelectSpareParts.html',
            pageParam: {
                name: "emequipmentMaintenance-detail",
                equipCode: api.pageParam.equipcode
            }
        });
    }

    //备件选择后回调函数
    function sparePartsSelected(dataList) {
        var list = dataList;//JSON.parse(dataList);
        var html = "";
        var listBj = [];//已选择备件，若备件已存在将不会重复添加
        $("ul[id=tbodyMrlHtml] li[name=litr]").each(function (index) {
            var mtlCode = document.getElementsByName("mtlCode")[index].innerText;
            listBj.push(mtlCode);
        })
        for (i in list) {
            if (listBj.indexOf(list[i].code) == -1) {
                html += `
            <li name='litr' style='margin-top: 10px; height: 120px;color: grey;background-color:white;border-radius:8px;box-shadow: 0 2px 4px rgba(0,0,0,0.1);overflow:hidden;'>
                <!-- 左侧图片区域 -->
                    <div style='width: 30%;height: 100%;float: left;margin-right: 1%'>
                        ${list[i].ext12 ?
                        `<img src='${list[i].ext12}' style='width: 100%; height: 100%;object-fit: cover;'>`
                        :
                        `<div class='aui-text-center' style='color: #fff;font-size: 15px;height: 100%;padding-top: 45%;background-color:#ccc;'>
                                    <span>未上传图片</span>
                                </div>`
                    }
                    </div>
                
                    <!-- 右侧信息区域 -->
                    <div style='width: 67%;height: 100%;float: left;font-size:14px;text-align: left;padding-left: 2%;box-sizing: border-box;'>
                        <!-- 名称 -->
                        <div style='font-weight: bold;font-size:16px;color: black;margin-top:10px;'>
                            <span name='mtlName'>${list[i].name || ''}</span>
                        </div>
                
                        <!-- 备件编码 -->
                        <div>备件编码：<span name='mtlCode'>${list[i].code || ''}</span></div>
                
                        <!-- 数量输入框和删除按钮在同一行，使用flex布局 -->
                        <div style='display: flex; align-items: center; justify-content: space-between; margin-top: 5px;'>
                            <div style='display: flex; align-items: center; width: 60%;'>
                                <div class='aui-list-item-label ui-selectee list-tr-title' style='margin-right: 5px;'>数量:</div>
                                <input type='number' name='qty' oninput='value = value.replace(/[^0-9]/g, "").replace(/^0+(\d+)/, "$1")' value='${list[i].quantity}' 
                                       style='border-top-style: none; border-right-style: none; border-left-style: none; 
                                              border-bottom-style: solid;border-bottom-width: 0.5px; width: 50%;'>
                            </div>
                            <div class='aui-list-item-right aui-btn ui-selectee delMrl' 
                                 style='background:#d41a10;color:#f5f5f5; margin: 0;'>删除</div>
                        </div>
                    </div>
                </li>
                `;

            }
            // console.log("html:"+html);
        }
        $api.append($api.byId("tbodyMrlHtml"), html);

    }

    //删除备件
    $(document).on('click', '.delMrl', function () {
        var othis = this;
        api.confirm({
            title: '删除',
            msg: '确认删除该备件信息？',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                $(othis).parent().parent().parent().remove();
            } else { }
        });


    })

    //完成前校验表单数据是否完整
    function doCompleteBefore() {
        //开始时间
        var beginDate = formatDateTime("beginDate");//$("#beginDate").val();
        if (beginDate == null || beginDate == undefined || beginDate == '') {
            api.toast({
                msg: "请选择开始时间！",
                duration: 3000
            });
            return;
        }
        //结束时间
        var endDate = formatDateTime("endDate");//$("#endDate").val();
        if (endDate == null || endDate == undefined || endDate == '') {
            api.toast({
                msg: "请选择结束时间！",
                duration: 3000
            });
            return;
        }
        //保养用时
        var consumeTime = $("#consumeTime").val();
        //是否停机
        var ext05 = "";
        const checkedRadio5 = document.querySelector('input[name="ext05"]:checked');
        if (checkedRadio5) {
            // console.log("ext05555555:");
            ext05 = checkedRadio5.value;
        }
        if (ext05 == null || ext05 == undefined || ext05 == '') {
            api.toast({
                msg: "请选择是否停机！",
                duration: 3000
            });
            return;
        }
        var ext08 = "";
        if ('1' == ext05) {//显示停机时长
            ext08 = $("#ext08").val();
            if (ext08 == null || ext08 == undefined || ext08 == "") {
                api.toast({
                    msg: "请录入停机时长！",
                    duration: 3000
                });
                return;
            }
        }
        //是否更换备件
        var ext06 = "";
        const checkedRadio6 = document.querySelector('input[name="ext06"]:checked');
        if (checkedRadio6) {
            // console.log("6666666666:");
            ext06 = checkedRadio6.value;
        }
        if (ext06 == null || ext06 == undefined || ext06 == '') {
            api.toast({
                msg: "请选择是否更换备件！",
                duration: 3000
            });
            return;
        }
        var listBj = [];
        if ("1" == ext06) {
            //需要更换备件、获取备件信息
            if ($("ul[id=tbodyMrlHtml] li[name=litr]").length == 0) {
                api.toast({
                    msg: "请选择备件！",
                    duration: 3000
                });
                return;
            }
            $("ul[id=tbodyMrlHtml] li[name=litr]").each(function (index) {
                var mtlName = document.getElementsByName("mtlName")[index].innerText;
                var mtlCode = document.getElementsByName("mtlCode")[index].innerText;
                var qty = document.getElementsByName("qty")[index].value;
                var mo = {
                    planId: sysid,
                    planClass: '0', //0保养计划/1检修计划/2故障维修/3点检计划
                    mtlName: mtlName,
                    mtlCode: mtlCode,
                    qty: qty
                }
                //只有数量大于0 才提交
                if (parseFloat(qty) > 0) {
                    listBj.push(mo);
                }

            })
        }
        //班组主键
        var ext01 = "";
        //保养人员信息
        var listEmp = [];

        $("ul[id=tbodyHtml] li[name=litr]").each(function (index) {
            var empName = document.getElementsByName("empName")[index].innerText;
            var empCode = document.getElementsByName("empCode")[index].innerText;
            var actualtime = document.getElementsByName("actualtime")[index].value;
            ext01 = document.getElementById("teamID" + empCode).value;
            var mo = {
                planClass: '0', //0保养计划/1检修计划/2故障维修
                empName: empName,
                empCode: empCode,
                actualtime: actualtime
            }
            //只有实际工时大于0 才提交
            if (parseFloat(actualtime) > 0) {
                listEmp.push(mo);
            }

        })
        if (listEmp.length == 0) {
            api.toast({
                msg: "请选择保养人员！",
                duration: 3000
            });
            return;
        }

        if (ext01 == null || ext01 == undefined || ext01 == '') {
            api.toast({
                msg: "请选择保养班组！",
                duration: 3000
            });
            return;
        }
        //维修描述
        var ext07 = $("#ext07").val();
        if (ext07 == null || ext07 == undefined || ext07 == '') {
            api.toast({
                msg: "请录入维修描述！",
                duration: 3000
            });
            return;
        }
        // 获取 id 为 "addpic" 的容器内所有 img
        var content = document.getElementById('imgslist');
        var imgs = content.getElementsByTagName('img');
        var names = [];
        for (var i = 0; i < imgs.length; i++) {
            var img = imgs[i];
            if (img.hasAttribute('id')) {
                //判断图片是否有id属性，只有之前保存过的图片才有id 即文件名称
                names[i] = img.id;

            } else {
                var srcStr = img.getAttribute('src');
                var arrs = srcStr.split('\/');
                var nameStr = arrs[arrs.length - 1];
                if ("add.jpg" != nameStr) {
                    names[i] = nameStr;
                }
            }

        }
        if (names.length == 0) {
            api.toast({
                msg: "请上传保养图片！",
                duration: 3000
            });
            return;
        }
        doComplete('3');
    }

    //完成
    function doComplete(taskState) {
        //设备任务单主键
        var sysid = api.pageParam.taskid;
        var taskCode = api.pageParam.taskCode;
        var equipcode = api.pageParam.equipcode;
        //开始时间
        var beginDate = formatDateTime("beginDate");//$("#beginDate").val();
        //结束时间
        var endDate = formatDateTime("endDate");//$("#endDate").val();
        //保养用时
        var consumeTime = $("#consumeTime").val();
        //是否停机
        var ext05 = "";
        const checkedRadio5 = document.querySelector('input[name="ext05"]:checked');
        if (checkedRadio5) {
            // console.log("ext05555555:");
            ext05 = checkedRadio5.value;
        }
        var ext08 = "";
        if ('1' == ext05) {//显示停机时长
            ext08 = $("#ext08").val();
        }
        //是否更换备件
        var ext06 = "";
        const checkedRadio6 = document.querySelector('input[name="ext06"]:checked');
        if (checkedRadio6) {
            // console.log("6666666666:");
            ext06 = checkedRadio6.value;
        }
        var listBj = [];
        // console.log("6666666666:"+ext06);
        if ("1" == ext06) {
            //需要更换备件、获取备件信息
            // if($("ul[id=tbodyMrlHtml] li[name=litr]").length==0)
            $("ul[id=tbodyMrlHtml] li[name=litr]").each(function (index) {
                var mtlName = document.getElementsByName("mtlName")[index].innerText;
                var mtlCode = document.getElementsByName("mtlCode")[index].innerText;
                var qty = document.getElementsByName("qty")[index].value;
                var mo = {
                    planId: sysid,
                    planClass: '0', //0保养计划/1检修计划/2故障维修/3点检计划
                    mtlName: mtlName,
                    mtlCode: mtlCode,
                    qty: qty
                }
                //只有数量大于0 才提交
                if (parseFloat(qty) > 0) {
                    listBj.push(mo);
                }

            })
        }
        //班组主键
        var ext01 = "";
        //保养人员信息
        var listEmp = [];
        $("ul[id=tbodyHtml] li[name=litr]").each(function (index) {
            var empName = document.getElementsByName("empName")[index].innerText;
            var empCode = document.getElementsByName("empCode")[index].innerText;
            var actualtime = document.getElementsByName("actualtime")[index].value;
            ext01 = document.getElementById("teamID" + empCode).value;
            var mo = {
                planId: sysid,
                planClass: '0', //0保养计划/1检修计划/2故障维修
                empName: empName,
                empCode: empCode,
                actualtime: actualtime
            }
            //只有实际工时大于0 才提交
            if (parseFloat(actualtime) > 0) {
                listEmp.push(mo);
            }

        })

        //维修描述
        var ext07 = $("#ext07").val();
        // 获取 id 为 "addpic" 的容器内所有 img
        var content = document.getElementById('imgslist');
        var imgs = content.getElementsByTagName('img');
        var names = [];
        // console.log("imgsimgsimgsimgs666:" + JSON.stringify(content.innerHTML));
        // console.log("imgsimgsimgsimgs:" + JSON.stringify(content));
        // console.log("imgsimgsimgsimgs222:" + JSON.stringify(imgs));
        for (var i = 0; i < imgs.length; i++) {
            var img = imgs[i];
            if (img.hasAttribute('id')) {
                //判断图片是否有id属性，只有之前保存过的图片才有id 即文件名称
                names[i] = img.id;

            } else {
                var srcStr = img.getAttribute('src');
                var arrs = srcStr.split('\/');
                var nameStr = arrs[arrs.length - 1];
                if ("add.jpg" != nameStr) {
                    names[i] = nameStr;
                }
            }

        }
        var picNames = JSON.parse(JSON.stringify(names));
        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un'); //登录用户
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/emequipmentMaintenanceSave";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un, //登录用户
                taskId: sysid, //设备任务单主键
                taskCode: taskCode,
                taskState: taskState,//0编辑/1审核/2进行/3完成
                equipcode: equipcode,
                beginDate: beginDate, //开始时间
                endDate: endDate, //结束时间
                consumeTime: consumeTime, //实际工时
                ext05: ext05,  //是否停机
                ext06: ext06,  //是否更换备件
                ext07: ext07,  //维修描述
                ext01: ext01, //班组主键
                picNames: picNames,//保养图片
                listEmp: listEmp, //保养人员
                listBj: listBj,//备件
                listItem: listItem //检验项
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                    closeWin();
                    api.execScript({
                        name: api.pageParam.name,
                        script: 'doSearch()'
                    });

                } else if (myobj.code == '1') {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });



    }
</script>

</html>